//
//  OHttpSession.m
//  soccer
//
//  Created by 上官千城 on 15/9/19.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "OHttpSession.h"
#import "AppDelegate.h"

@implementation OHttpSession

-(instancetype)initWithSessionId:(NSString*)sessionId lastTime:(NSInteger)lastTime expire:(NSInteger)expire
{
    self = [super init];
    if (self) {
        self.sessionId = sessionId;
        self.lastTime = lastTime;
        self.expire = expire;
        return self;
    }
    return nil;
}

+(OHttpSession*) getSession:(NSString*)path
{
    AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    
    return [appDelegate.httpSessionDic objectForKey:path];
}

+(void) setSession:(OHttpSession*)session
{
    [session update];
}

+(OHttpSession*) addSession:(NSString*)path sessionId:(NSString*)sessionId lastTime:(NSInteger)lastTime expire:(NSInteger)expire
{
    OHttpSession* session = [[OHttpSession alloc] initWithSessionId:sessionId lastTime:lastTime expire:expire];
    AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

    [appDelegate.httpSessionDic setObject:session forKey:path];
    
    return session;
}

+(void) addSession:(NSString*)path session:(OHttpSession *)session
{
    AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    [appDelegate.httpSessionDic setObject:session forKey:path];
}

+(void) removeSession:(NSString*)path
{
    AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    [appDelegate.httpSessionDic delete:path];
    //TODO:从数据库中删除
    
}

-(void) update
{
    //TODO:向数据库设置
    
}

@end
